﻿Public Class CINNERLabelState4 : Inherits CStateBase

    ''' <summary>
    ''' 実行可能かを判断する
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function IsEnter(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CINNERLabelState4.IsEnter")
        If CCommon.isInStr(task.ActionCd, "LABEL-IN") Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 実行メソッド
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExecute(ByVal task As CTaskBase) As CStateBase
        Dim nextState As CStateBase
        Dim pdaTask As CPDATask4 = DirectCast(task, CPDATask4)
        Debug.WriteLine("CINNERLabelState4.DoExecute")
        Dim labelType As String = "IN"
        Dim readText As String = task.ProcessText
        Dim sysItemCd As String = CCommon.TrimCode(readText, CCommon.EnumGetString.LBL_IN_ITEM_CD)
        Dim inBoxQty As Integer = CCommon.From36To10(CCommon.TrimCode(readText, CCommon.EnumGetString.LBL_IN_QTY))
        Dim orderCd As String = ""
        Dim deliveryCd As String = ""
        Dim uniqueCd As String = readText

        ''読込み済みのラベルではないか確認（ユニークコード）N:アラート
        Dim uniqueCdInfo As CPDATask4.strctUniqueCdInfo = Nothing
        uniqueCdInfo.labelType = labelType
        uniqueCdInfo.sysItemCd = sysItemCd
        uniqueCdInfo.uniqueCd = uniqueCd
        uniqueCdInfo.readDateTime = Now()
        uniqueCdInfo.empCd = pdaTask.EmpInfo.empNo

        Dim msg As String = pdaTask.uniqueCdInfoStandardLogic(uniqueCdInfo, True)
        If msg <> "" Then
            ''警告
            pdaTask.alertMsg(msg, task)
        Else
            If inBoxQty = 0 Then
                ''端数ラベルの場合、入力を求める
                inBoxQty = pdaTask.inputMsg(0, CCommon.CNS_MSG_022, task)
            End If

            Dim nowDatetime As Date = Now()
            Dim readData As CPDATask4.strctDataList = Nothing
            With readData
                .correctCd = "1"
                .empNo = pdaTask.EmpInfo.empNo
                .orderCd = orderCd
                .deliveryCd = deliveryCd
                .sysItemCd = sysItemCd
                .uniqueCd = uniqueCd
                .actionQty = inBoxQty
                .befActionQty = 0
                .actionDate = nowDatetime.ToString("yyyyMMdd")
                .actionTime = nowDatetime.ToString("HHmmss")
                .errorCd = "OK"
                .labelType = labelType

            End With
            pdaTask.listClear()
            pdaTask.addDataList(pdaTask.listView(readData))
        End If

        task.ActionCd = "LABEL"
        task.ProcessText = ""
        nextState = GetNextState(task)
        Return nextState
    End Function

    ''' <summary>
    ''' 終了メソッド(未使用)
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExit(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CINNERLabelState4.DoExit")
        Return True
    End Function


End Class
